#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/wait.h>

// ex: 子进程发送暂停信号， 父进程发送终止信号
int main(int argc, char const *argv[])
{
    pid_t pid = fork();
    if (pid < 0 ) {
        perror("fork error");
        exit(0);
    } else if (pid == 0) {
        printf("child process\n");
        printf("child process pid:%d\n", getpid());
        raise(SIGSTOP);// 子进程发送SIGSTOP信号
        printf("child pricess exit : %d \n", getpid());
        exit(EXIT_SUCCESS);
    } else if (pid >0) {
            printf("parent process\n");
            sleep(1); // 让子进程先执行
            // 父进程发出终止信号
            int ret = kill(pid, SIGKILL);
            if (ret == 0) {
                printf("kill success\n");
            }
            waitpid(pid, NULL, 0);//等待子进程退出
            printf("parent process exit : %d \n", getpid());
            exit(EXIT_SUCCESS);
    }
    return 0;
}